package com.homedo.odin.solution.enumcode.advertising;

import java.util.Arrays;
import lombok.Getter;

/**
 * @author: zhanglei
 * @date: 2018/4/17
 * @Description: 广告类型
 */
@Getter
public enum PositionTypeEnum {
    TEXT(0, "文本"),
    PIC(1, "图片"),
    VIDEO(2, "视频");

    private Integer dbValue;
    private String displayValue;

    PositionTypeEnum(Integer dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(PositionTypeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(PositionTypeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(PositionTypeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
